package com.bdqn.BookManage.servlet;

import com.bdqn.BookManage.biz.BookInfoBiz;
import com.bdqn.BookManage.biz.BookTypeBiz;
import com.bdqn.BookManage.biz.impl.BookInfoBizImpl;
import com.bdqn.BookManage.biz.impl.BookTypeBizImpl;
import com.bdqn.BookManage.po.BookInfo;
import com.bdqn.BookManage.po.BookType;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : CP
 * @version: 1.0
 * @program : BookManage
 * @description : 图书详情处理器
 * @date : 2020-07-28 11:23
 **/
@WebServlet("/xq")
public class BookParticularsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        BookInfoBiz bookInfoBiz = new BookInfoBizImpl();
        BookTypeBiz typeBiz = new BookTypeBizImpl();
        String bookId = req.getParameter("id");

        /* 获取值 */
        BookInfo bookInfo = bookInfoBiz.querBookInfo(Integer.valueOf(bookId));
        req.setAttribute("bookInfo",bookInfo);
        BookType bookType = typeBiz.queryById(bookInfo.getTypeId());
        req.setAttribute("typeName",bookType);
        /* 修改页面跳转 */
        req.getRequestDispatcher("bookParticulars.jsp").forward(req, resp);
    }
}
